<!DOCTYPE html>
<meta charset=utf-8>
<title>Submitting element directionality: the dirname attribute</title>
<link rel="author" title="Kolupaev Dmitry" href="mailto:dmitry.klpv@gmail.com">
<link rel=help href="https://html.spec.whatwg.org/multipage/#submitting-element-directionality:-the-dirname-attribute">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div dir="rtl">
  <form action="dirname-ltr-iframe.html" method=get target="iframe">
    <p><label>Comment: <input type=text name="comment" dirname="comment.dir" required/></label></p>
    <p><button type=submit>Post Comment</button></p>
  </form>
</div>
<iframe name="iframe"></iframe>
<script>
  function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(document.querySelector("iframe").contentWindow.location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  }

  var t = async_test("submit element directionality");
  document.querySelector("input").value = "foobar";
  document.querySelector("button").click();

  var iframe = document.querySelector("iframe");
  iframe.onload = t.step_func(function() {
    // The initial about:blank load event can be fired before the form navigation occurs.
    // See https://github.com/whatwg/html/issues/490 for more information.
    if(iframe.contentWindow.location.href == "about:blank") { return; }

    assert_equals(getParameterByName("comment.dir"), "rtl");

    t.done();
  });
</script>
